/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gl;

import carte.Carte;
import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import perso.Personnage;

/**
 *
 * @author Administrateur
 */
public class DisplayMap implements Itf_Display {
    public JLabel[][] tabPerso;
    @Override
    public void displayInfo(ArrayList<Personnage> listPerso, Carte carte) {
       for (int x = 0; x < tabPerso.length; x++) {
            for (int y = 0; y < tabPerso[x].length; y++) {
                boolean persofit = false;
                if (carte.getPosObj()[x][y] != null) {
                    ImageIcon image = new javax.swing.ImageIcon(getClass().getResource(carte.getPosObj()[x][y].getValue()));
                    tabPerso[x][y].setIcon(image);
                    persofit = true;
                }

                Iterator<Personnage> itr = listPerso.iterator();
                while (itr.hasNext()) {
                    Personnage perso = itr.next();
                    ImageIcon image = new javax.swing.ImageIcon(getClass().getResource(perso.getImage()));
                    if (x == perso.px && y == perso.py) {
                        tabPerso[perso.px][perso.py].setIcon(image);
                        persofit = true;
                    }

                }
                if (!persofit) {
                    tabPerso[x][y].setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/empty.jpg")));
                }
            }
        }
    }

    @Override
    public void setParam(int nbrX, int nbrY,JPanel panel_game) {
                GridLayout grid = new GridLayout(nbrX, nbrY);
        panel_game.setLayout(grid);
        tabPerso = new JLabel[nbrX][nbrY];
        for (int x = 0; x < nbrX; x++) {
            for (int y = 0; y < nbrY; y++) {
                tabPerso[x][y] = new JLabel();

                //ImageIcon image = new ImageIcon("images/chef.jpg");
                tabPerso[x][y].setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/empty.jpg")));

                panel_game.add(tabPerso[x][y]);
            }
        }
    }
    
}
